package com.hb.game.pk.adpter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hb.game.pk.APP;
import com.hb.game.pk.R;
import com.hb.game.pk.beans.ClickRedDean;
import com.hb.game.pk.utils.StringUtils;

public class OpenRedListAdpter extends BaseQuickAdapter<ClickRedDean.DataBean.ListBean, BaseViewHolder> {
    public OpenRedListAdpter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, ClickRedDean.DataBean.ListBean item) {
//        Glide.with(mContext).load(item.getUrl())
//                .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(5, 0, RoundedCornersTransformation.CornerType.ALL)))
//                .into(imageView);
        int res = 0;
        if (item.getAvatar() != null)
            res = getHeadRes(item.getAvatar());
        else
            res = getHeadRes(item.getFace());
        helper.setImageResource(R.id.iv_head, res);
        helper.setText(R.id.tv_name, item.getUsername());
        helper.setText(R.id.tv_time, item.getRecivetime());
        if (this.getData().size() == 7 && item.getIs_best().equals("1")) {
            helper.setVisible(R.id.iv_best, true);
        }
        if (item.getIs_robot().equals("1")) {
            if (getData().size() != 7)
                helper.setText(R.id.tv_money, String.format("%.1f", Float.parseFloat(item.getMoney()) / 100f) + "*");
            else {
                helper.setText(R.id.tv_money, String.format("%.2f", Float.parseFloat(item.getMoney()) / 100f));
            }
            helper.setImageResource(R.id.iv_head, R.mipmap.ic_miansi);
        } else {
            helper.setText(R.id.tv_money, String.format("%.2f", Float.parseFloat(item.getMoney()) / 100f));
        }
    }

    private int getHeadRes(String avatar) {
        int res = R.mipmap.ic_head_normal;
        String trim = StringUtils.getString(avatar);
        if (StringUtils.isEmpty(trim)) {
            res = R.mipmap.ic_head_normal;
        } else {
            if (StringUtils.isNumber(trim)) {
                int i = Integer.parseInt(trim);
                res = APP.headResource.get(i - 1);
            }
        }
        return res;
    }
}
